package com.xaicode.template.minio.controller;

import io.minio.MinioClient;
import io.minio.errors.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;

/**
 * @author Locker
 * @date 2021/8/3 0003 17:05
 */
@RestController
@RequestMapping("minio")
public class MinioController {

    private String ENDPOINT = "https://121.36.45.234:29004";
    private String ACCESS_KEY = "aerosatlink";
    private String SECRET_KEY = "P@ssw0rd01!";
    private String bucketName = "ground";
    private String objectName = "20230613151009120/中国航天箭头图标.png";


    @RequestMapping("p1")
    public Object first() throws ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, InvalidExpiresRangeException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {

        MinioClient minioClient = MinioClient.builder()
                .endpoint(ENDPOINT)
                .credentials(ACCESS_KEY, SECRET_KEY)
                .build();

        String s = minioClient.presignedGetObject(bucketName, objectName,
                (int) TimeUnit.SECONDS.toSeconds(30));

        return s;
    }

}
